package com.easyhouse.common.pojo;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class UserValidator implements Validator {
    /**
     * 检查类型的方法
     */
    @Override
    public boolean supports(Class<?> clz) {
        return User.class.equals(clz);
    }

    /**
     * 检查两次密码是否一致
     */
    @Override
    public void validate(Object target, Errors errors) {
        User user = (User) target;
        String psw = user.getUserPassword();
        String psw2 = user.getUserPassword2();
        if(!psw.equals(psw2)){
            errors.rejectValue("password2",null,"两次密码不一致！");
        }
    }
}